<template>
  <div class="app-container">
    <el-form v-show="showSearch" ref="queryForm" :model="queryParams" size="small" :inline="true" label-width="90px">
      <el-form-item
        label="产品编号："
        prop="productId"
      >
        <el-input
          v-model="queryParams.productId"
          placeholder="请输入"
          clearable
          style="width: 250px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="产品名称：" prop="productName">
        <el-input
          v-model="queryParams.productName"
          placeholder="请输入"
          clearable
          style="width: 250px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="产品类型：" prop="serviceType">
        <el-select v-model="queryParams.serviceType" placeholder="请选择" clearable style="width: 250px">
          <!-- 字典状态，dict.type.你添加进字典的类型 -->
          <el-option v-for="dict in dict.type.channel_service_type" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <div style="margin-right: 50px;">
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </div>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <router-link :to="'/production/collaborativeProduct-stepone/index'" class="link-type">
          <el-button
            v-hasPermi="['system:post:add']"
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
          >新增</el-button>
        </router-link>
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          v-hasPermi="['system:post:export']"
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
        >导出</el-button>
      </el-col> -->
      <right-toolbar :show-search.sync="showSearch" @queryTable="getList" />
    </el-row>
    <!-- data=你后台查出的数据 -->
    <el-table v-loading="loading" :data="productionList" @selection-change="handleSelectionChange">
      <el-table-column label="产品编号" align="center" prop="productId" />
      <el-table-column label="产品名称" align="center" prop="productName" />
      <el-table-column label="状态" align="center" prop="productStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.production_info_production_status" :value="scope.row.productStatus" />
        </template>
      </el-table-column>
      <el-table-column label="渠道数" align="center" prop="channelNum" />
      <el-table-column label="最后更新人" align="center" prop="lastPerson" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">

          <router-link :to="'/production/collaborativeProduct-stepone/indexs/' + scope.row.productId" class="link-type">
            <el-button
              v-hasPermi="['system:post:query']"
              size="mini"
              type="text"
              icon="el-icon-edit"
            >查看</el-button>
          </router-link>
          <router-link :to="'/production/collaborativeProduct-stepone/index/' + scope.row.productId" class="link-type">
            
            
            <el-button
              v-hasPermi="['system:post:edit']"
              size="mini"
              type="text"
              icon="el-icon-edit"
            >编辑</el-button>
          </router-link>
          <!-- <el-button
            v-if="scope.row.productStatus !== 1"
            v-hasPermi="['system:post:remove']"
            size="mini"
            type="text"
            icon="el-icon-open"
            @click="enableProduction(scope.row.productId)"
          >启用</el-button>
          <el-button
            v-if="scope.row.productStatus == 1"
            v-hasPermi="['system:post:remove']"
            size="mini"
            type="text"
            icon="el-icon-turn-off"
            @click="disableProduction(scope.row.productId)"
          >禁用</el-button> -->
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
// 导入api
import { listProduction, enableProductionById, disableProductionById, findProduct } from '@/api/production'
export default {
  name: 'Pro',
  // 字典导入
  dicts: ['production_info_production_status','channel_service_type'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 产品数据
      productionList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        productId: undefined,
        productName: undefined,
        productStatus: undefined,
        usage: undefined,
        serviceType: undefined
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      this.loading = true
      findProduct(this.addDateRange(this.queryParams)).then(response => {
        console.log(response)
        this.productionList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    reset() {
      this.form = {
        code: 1,
        status: '0'
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      // console.log(queryParams)
      // debugger
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    handleExport() {
      this.download('product/export', {
        ...this.queryParams
      }, `role_${new Date().getTime()}.xlsx`)
    },
    enableProduction(productionId) {
      enableProductionById(productionId)
      window.location.reload()   
    },
    disableProduction(productionId) {
      disableProductionById(productionId)
      window.location.reload()
    }
  }

}

</script>

<style>

</style>
